import java.text.SimpleDateFormat
import java.util.Date
import java.text.DateFormat
import grails.converters.JSON
class SchoolController {

    def index = { }
 

 
    def createSchool = {
        log.info("params.start="+params.start)
        log.info("params.end="+params.end)
        DateFormat   format   =   new   SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   
        Date   start
        Date   end
        try{   
            start   =   format.parse(params.start);   
            end   =   format.parse(params.end);   
        }catch(Exception   ex){   
            start = new Date()
            end = new Date()
        }                 


        log.info("params.hostId="+params.hostId)
        def school = School.findByHostId(params.hostId.toLong())
        if(!school){
            log.info("不存在吗？？？")
            school = new School()
        }
        school.name = URLDecoder.decode(params.name, "UTF-8")
        school.subDomain = params.subDomain
        school.domain = params.domain
        school.enable = params.enable
        school.area = params.area
        school.hostId = params.hostId.toLong()
        school.start = start
        school.end = end
        if (school.hasErrors() || !school.save(flush: true)) {            
             render (['message' : '在blog中学校创建失败！','success': false] as JSON)
        }
        render (['message' : '在blog中学校创建成功！','success': true] as JSON)
    }
}
